package com.study.thread;

/**
 * @Author hupengming
 * @ClassName TestThread
 * @Date 2023-05-19  10:25
 * @Version 1.0
 */
public class TestThread {

    public static void m1(){
        Thread t1 = new Thread(() -> {
            System.out.println(Thread.currentThread().isDaemon());
            System.out.println(Thread.currentThread().getName() + "是"
                    + (Thread.currentThread().isDaemon() ? "守护线程":"用户线程"));

        },"t1");
        t1.setDaemon(true);
        t1.start();

        Thread t2 = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "线程启动成功");
            int i = 0;
            while (i < 5){
                try {
                    Thread.sleep(5000);
                    System.out.println("i = " + (i++));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"t2");
        t2.start();
        System.out.println("主线程执行完毕:" + Thread.currentThread().getName());
    }

    public static void main(String[] args) throws InterruptedException {

    }

}
